﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="OrderContent.cs" company="Open Trader">
//   Copyright (c) David Denis (david.denis@systemathics.com)
// </copyright>
// <summary>
//   |  Open Trader - The Open Source Systematic Trading Platform
//   |
//   |  This program is free software: you can redistribute it and/or modify
//   |  it under the terms of the GNU General Public License as published by
//   |  the Free Software Foundation, either version 2 of the License, or
//   |  (at your option) any later version.
//   |
//   |  This program is distributed in the hope that it will be useful,
//   |  but WITHOUT ANY WARRANTY; without even the implied warranty of
//   |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   |  GNU General Public License for more details.
//   |
//   |  You should have received a copy of the GNU General Public License
//   |  along with this program.  If not, see http://www.gnu.org/licenses
//   |
//   |  Up to date informations about Open Trader can be found at :
//   |    http://opentrader.org
//   |    http://opentrader.codeplex.com
//   |
//   |  For professional services, please visit us at :
//   |    http://www.systemathics.com
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Org.OpenTrader.Extensions.ReportBuilder
{
    #region Using Directives

    using System.Collections.Generic;

    using Framework.Forge.DataModel;

    using Org.OpenTrader.Framework;
    using Org.OpenTrader.Framework.DataModel;

    #endregion

    /// <summary>
    /// The order content.
    /// </summary>
    public class OrderContent
    {
        #region Constants and Fields

        /// <summary>
        /// The db order execution.
        /// </summary>
        private DBOrderExecution dbOrderExecution;

        /// <summary>
        /// The db order status.
        /// </summary>
        private DBOrderStatus dbOrderStatus;

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="OrderContent"/> class.
        /// </summary>
        /// <param name="dbOrderExecution">
        /// The db order execution.
        /// </param>
        public OrderContent(DBOrderExecution dbOrderExecution)
        {
            this.dbOrderExecution = dbOrderExecution;
            this.TimeStamp = PrettyPrinter.Timings.Format(this.dbOrderExecution.TimeStamp);
            this.Type = "Execution";
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="OrderContent"/> class.
        /// </summary>
        /// <param name="dbOrderStatus">
        /// The db order status.
        /// </param>
        public OrderContent(DBOrderStatus dbOrderStatus)
        {
            this.dbOrderStatus = dbOrderStatus;
            this.TimeStamp = PrettyPrinter.Timings.Format(this.dbOrderStatus.TimeStamp);
            this.Type = this.dbOrderStatus.Status;
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets Counterparty.
        /// </summary>
        public string Counterparty
        {
            get
            {
                return (this.dbOrderExecution != null) ? this.dbOrderExecution.CounterParty : string.Empty;
            }
        }

        /// <summary>
        /// Gets Price.
        /// </summary>
        public double Price
        {
            get
            {
                return (this.dbOrderExecution != null) ? this.dbOrderExecution.Price : -1;
            }
        }

        /// <summary>
        /// Gets Quantity.
        /// </summary>
        public int Quantity
        {
            get
            {
                return (this.dbOrderExecution != null) ? this.dbOrderExecution.Quantity : -1;
            }
        }

        /// <summary>
        /// Gets TimeStamp.
        /// </summary>
        public string TimeStamp { get; private set; }

        /// <summary>
        /// Gets Type.
        /// </summary>
        public string Type { get; private set; }

        #endregion

        /// <summary>
        /// Comparer for sorting and searching Author collection by Id.
        /// </summary>
        public class Comparer : IComparer<OrderContent>
        {
            #region Implemented Interfaces

            #region IComparer<OrderContent>

            /// <summary>
            /// The compare.
            /// </summary>
            /// <param name="orderContent1">
            /// The order content 1.
            /// </param>
            /// <param name="orderContent2">
            /// The order content 2.
            /// </param>
            /// <returns>
            /// The compare.
            /// </returns>
            public int Compare(OrderContent orderContent1, OrderContent orderContent2)
            {
                return string.Compare(orderContent1.TimeStamp, orderContent2.TimeStamp);
            }

            #endregion

            #endregion
        }
    }
}